using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DuAnDAO
/// </summary>
public class DuAnDAO:DataProvider
{
    public ArrayList LayMang_DuAn()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_DuAn", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DuAnDTO dadto = new DuAnDTO();
                dadto.MaDuAn = dr.GetInt32(0);
                dadto.TenDuAn = dr.GetString(1);
                dadto.MoTaDuAn = dr.GetString(2);
                dadto.NoiDungThucHien = dr.GetString(3);
                dadto.NgayBatDau = dr.GetDateTime(4);
                dadto.NgayKetThuc = dr.GetDateTime(5);
                dadto.TinhTrang = dr.GetInt32(6);
                dadto.KinhPhi = dr.GetString(7);
                dadto.GhiChu = dr.GetString(8);
                dadto.Cap = dr.GetString(9);
                arr.Add(dadto);
            }
        }
        catch (Exception es)
        {
            throw es;
        }
        return arr;

    }
    public void insert(DuAnDTO dadto)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_DuAn", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@tenda", SqlDbType.NVarChar);
            cmd.Parameters["@tenda"].Value = dadto.TenDuAn.ToString();
            cmd.Parameters["@tenda"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@motaduan", SqlDbType.Text);
            cmd.Parameters["@motaduan"].Value = dadto.MoTaDuAn.ToString();
            cmd.Parameters["@motaduan"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@noidungthuchien", SqlDbType.Text);
            cmd.Parameters["@noidungthuchien"].Value = dadto.NoiDungThucHien.ToString();
            cmd.Parameters["@noidungthuchien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngaybd", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaybd"].Value = dadto.NgayBatDau.ToString();
            cmd.Parameters["@ngaybd"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngaykt", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaykt"].Value = dadto.NgayKetThuc.ToString();
            cmd.Parameters["@ngaykt"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tinhtrang", SqlDbType.Int);
            cmd.Parameters["@tinhtrang"].Value = dadto.TinhTrang;
            cmd.Parameters["@tinhtrang"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@kinhphi",SqlDbType.Money);
            cmd.Parameters["@kinhphi"].Value = dadto.KinhPhi;
            cmd.Parameters["@kinhphi"].Direction = ParameterDirection.Input;


            cmd.Parameters.Add("@ghichu", SqlDbType.Text);
            cmd.Parameters["@ghichu"].Value = dadto.GhiChu;
            cmd.Parameters["@ghichu"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@cap",SqlDbType.NVarChar);
            cmd.Parameters["@cap"].Value = dadto.Cap.ToString();
            cmd.Parameters["@cap"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (Exception es)
        {
            throw es;
        }
    }
    public void update(DuAnDTO dadto)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_DuAn", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@mada", SqlDbType.Int);
            cmd.Parameters["@mada"].Value = dadto.MaDuAn;
            cmd.Parameters["@mada"].Direction = ParameterDirection.Input;
                        
            cmd.Parameters.Add("@ngaybd", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaybd"].Value = dadto.NgayBatDau.ToString();
            cmd.Parameters["@ngaybd"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngaykt", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaykt"].Value = dadto.NgayKetThuc.ToString();
            cmd.Parameters["@ngaykt"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tinhtrang", SqlDbType.Int);
            cmd.Parameters["@tinhtrang"].Value = dadto.TinhTrang;
            cmd.Parameters["@tinhtrang"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@kinhphi", SqlDbType.Money);
            cmd.Parameters["@kinhphi"].Value = dadto.KinhPhi;
            cmd.Parameters["@kinhphi"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
	public DuAnDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}
